"""
pi/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 ...
"""

# O(n)
def pi1(n):
    pi = 0
    sign = 1
    for i in range(1, n + 1, 2): 
        pi += sign * (1 / i)
        print(sign * (1/i))
        sign *= -1
    return pi * 4


# 无输入 O(1)
def pi2():
    pi = 0
    sign = 1
    pre = 999
    i = 1
    delta = 0.000001
    
    while (abs(pi - pre) > delta):
        pre = pi
        pi += sign * (1 / i)
        sign *= -1
        i += 2
    return pi * 4  

print(pi2())